package Year22_Month04.day09;

import java.util.Arrays;

public class 比较含退格的字符串 {
    public static boolean backspaceCompare(String s, String t) {
        return  fun1(s).equals(fun1(t));
    }
    public static String fun1(String s){
        char[] arr = s.toCharArray();
        int left = 0;
        int right = 0;
        while(right < arr.length){
            if(arr[right] != '#'){
                arr[left] = arr[right];
                left++;
            }else{
                left--;
            }
            right++;
        };
        if(left == -1){
            return "";
        }
        StringBuffer mys = new StringBuffer();
        for (int i = 0; i < left; i++) {
            mys.append(arr[i]);
        }
        return mys.toString();
    }

    public static void main(String[] args) {
        String s = "ab#c";
        String t = "ad#c";
        System.out.println(backspaceCompare(s,t));
    }
}
